package com.gxa.dao.impl;


import com.gxa.dao.NoticeDao;
import com.gxa.dbutils.JdbcBuild;
import com.gxa.pojo.Notice;

import java.sql.SQLException;
import java.util.List;

public class NoticeDaoImpl extends JdbcBuild implements NoticeDao {

    @Override
    public List<Notice> queryNotice(Integer param01, Integer param02) throws SQLException {
        String sql = "select * from notice limit ?,?";
        Object[] params = {param01,param02};
        List<Notice> list = super.queryListEntity(Notice.class, sql, params);
        return list;
    }

    @Override
    public Integer countNotice() throws SQLException {
        String sql = "select count(*) from notice";
        int result = super.findAllForInt(sql, null);
        return result;
    }

    @Override
    public int add(Notice notice, String date) throws SQLException {
        String sql = "insert into notice(notice_num,notice_name,notice_type,notice_person,notice_content,notice_time) values(?,?,?,?,?,?)";
        Object[] params = {notice.getNotice_num(),notice.getNotice_name(),notice.getNotice_type(),notice.getNotice_person(),notice.getNotice_content(),date};
        int result = super.executeUpdate(sql, params);
        return result;
    }

    @Override
    public int del(String id) throws SQLException {
        String sql = "delete from notice where id=?";
        Object[] params = {id};
        int result = super.executeUpdate(sql, params);
        return result;
    }

    @Override
    public int mod(Notice notice, String date) throws SQLException {
        String sql = "update notice set notice_name=?,notice_time=?,notice_person=?,notice_content=?,notice_num=?,notice_type=? where id=?";
        Object[] params = {notice.getNotice_name(),date,notice.getNotice_person(),notice.getNotice_content(),notice.getNotice_num(),notice.getNotice_type(),notice.getId()};
        int result = super.executeUpdate(sql, params);
        return result;
    }

    @Override
    public List<Notice> searchNotice(Integer param01, Integer param02, String notice_name) throws SQLException {
        String sql = "select * from notice where notice_name=? limit ?,?";
        Object[] params = {notice_name,param01,param02};
        List<Notice> list = super.queryListEntity(Notice.class, sql, params);
        return list;
    }

    @Override
    public Integer countNotice(String notice_name) throws SQLException {
        String sql = "select count(*) from notice where notice_name=?";
        Object[] params = {notice_name};
        int result = super.findAllForInt(sql, params);
        return result;
    }
}
